<template>
  <div class="aui-card-list">
    <el-container>
      <el-aside width="180px">
        <el-card shadow="never" class="aui-card-list-left">
          <div class="title">
            <span>目录</span>
          </div>
          <div class="search">
            <el-input v-model="searchName" @change="filterChange" clearable :placeholder="$t('search')"></el-input>
          </div>
          <div class="body uni-scroll">
            <el-tree v-model="dirSelItems" @check="treeCheck" :data="dirList" :props="defaultTreeProps" :expand-on-click-node="false" :check-on-click-node="true" node-key="id" ref="treeList" accordion :show-checkbox="false" :default-expand-all="true" check-strictly :filter-node-method="filterNode">
            </el-tree>
          </div>
        </el-card>
      </el-aside>
      <el-main>
        <uni-list-query-card :queryShow="queryShow" @query-click="getDataList()" @click="(e)=>{this.queryShow=e}" @searchReset="searchReset()">
          <el-col :span="6">
            <el-form-item :label="$t('sysOss.fileOriName')">
              <el-input v-model="dataForm.fileOriName" :placeholder="$t('sysOss.fileOriName')" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item :label="$t('sysOss.bizId')">
              <el-input v-model="dataForm.bizId" :placeholder="$t('sysOss.bizId')" clearable></el-input>
            </el-form-item>
          </el-col>
        </uni-list-query-card>
        <el-card shadow="never" class="aui-card-list-body">
          <vxe-toolbar :setting="{immediate:true}">
            <template v-slot:buttons>
              <el-button v-if="$hasPermission('sys:user:save')" type="primary" @click="addOrUpdateHandle()">{{
                  $t('add') }}
              </el-button>
              <el-button v-if="$hasPermission('sys:user:delete')" type="danger" @click="deleteHandle()">{{
                  $t('deleteBatch') }}
              </el-button>
            </template>
            <template v-slot:tools>
              <el-button icon="el-icon-refresh" @click="getDataList()" circle></el-button>
              <el-dropdown trigger="click" style="padding-left: 5px;" placement="bottom">
                <el-button icon="el-icon-download" circle>
                </el-button>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item icon="el-icon-bottom" @click.native="exportHandle(true)">导出当前页</el-dropdown-item>
                  <el-dropdown-item icon="el-icon-download" @click.native="exportHandle()">全部导出
                  </el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </template>
          </vxe-toolbar>
          <!-- :export-config="{remote:true,exportMethod:({options})=>{return exportMethod(options,$refs.xTable)}}" -->
          <div class="aui-card-list-body-table">
            <vxe-table :loading="dataListLoading" :data="dataList" ref="xTable" auto-resize class="vxe-table-element" @select-change="dataListSelectionChangeHandleVex" @select-all="dataListSelectionAllChangeHandleVex" max-height="auto">
              <vxe-table-column type="checkbox" align="center" width="50"></vxe-table-column>
              <vxe-table-column prop="fileOriName" :label="$t('sysOss.fileOriName')"></vxe-table-column>
              <vxe-table-column prop="fileSaveName" :label="$t('sysOss.fileSaveName')"></vxe-table-column>
              <vxe-table-column prop="dirNames" :label="$t('sysOss.dirNames')"></vxe-table-column>
              <vxe-table-column prop="url" :label="$t('sysOss.url')">
                <template slot-scope="scope">
                  <a :href="$utils.getTokenUrl(scope.row.url)" target="_blank">{{ scope.row.url }}</a>
                  <!-- <a @click="$utils.downloadFile(scope.row.url)" target="_blank">{{ scope.row.url }}</a> -->
                </template>
              </vxe-table-column>
              <vxe-table-column prop="updateDate" :label="$t('common.updateDate')" width="140" align="center"></vxe-table-column>
              <vxe-table-column :label="$t('handle')" fixed="right" align="center" width="120">
                <template slot-scope="scope">
                  <el-button v-if="$hasPermission('oss:sysOss:delete')" type="text" icon="el-icon-delete" size="small" @click="deleteHandle(scope.row.id)">{{
                    $t('delete') }}
                  </el-button>
                  <el-button type="text" @click="preview(scope.row.url)">预览</el-button>
                </template>
              </vxe-table-column>
            </vxe-table>
            <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle">
            </el-pagination>
          </div>
        </el-card>
      </el-main>
    </el-container>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    <SecAdmin v-if="secAdminVisible" ref="secAdmin" @refreshDataList="getDataList"></SecAdmin>
    <UserDataScope :readOnly="false" v-if="userDataScopeVisible" ref="userDataScope"></UserDataScope>
  </div>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './sysOss-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/oss/sysOss/page',
        getDataListIsPage: true,
        deleteURL: '/oss/sysOss',
        deleteIsBatch: true,
        exportURL: '/oss/sysOss/export'
      },
      defaultTreeProps: {
        label: 'name',
        children: 'children'
      },
      dirList: [],
      dirSelItems: [],
      searchName: '',
      dataForm: {
        id: '',
        fileClass: '',
        fileContentType: '',
        fileExt: '',
        fileSize: '',
        fileMd5: '',
        fileOriName: '',
        fileSaveName: '',
        bizId: '',
        dirValue: '',
        ossType: '',
        ossId: '',
        localPhysicalPathname: '',
        creator: ''
      }
    }
  },
  watch: {
    dirSelItems: function (val) {
    }
  },
  created () {
    this.getDirList()
  },
  components: {
    AddOrUpdate
  },
  methods: {
    preview (url) {
      // 如果你的项目需要接入文件预览项目，达到对docx、excel、ppt、jpg等文件的预览效果，那么通过在你的项目中加入下面的代码就可以 成功实现：
      // var url = this.dataForm.fileUrl // 要预览文件的访问地址
      window.open('http://47.105.158.68/fileproview/onlinePreview?url=' + encodeURIComponent(url))

      // 新增多图片同时预览功能，接口如下：
      // var fileUrl =url1+"|"+"url2" //多文件使用“|”字符隔开
      // window.open('http://127.0.0.1:8012/picturesPreview?urls='+encodeURIComponent(fileUrl))
    },
    // 获取目录列表
    getDirList () {
      return this.$http.get('/oss/sysOssDir/treeList').then(({ data: res }) => {
        if (res.code !== 0) {
          return
        }
        this.dirList = res.data
      }).catch(() => { })
    },
    // 树 选中节点
    treeCheck (arg0) {
      // console.log(arg0)
      this.dirSelItems = this.$refs.treeList.getCheckedNodes()
      this.dataForm.dirValues = this.dirSelItems.map(c => c.value).join(',')
      this.getDataList()
    },
    // treeNodeclick (val) {
    //   this.dirSelItems = [val.dirValue]
    //   this.getDataList()
    // },
    filterNode: function (value, data) {
      if (!value) return true
      return data.name.indexOf(value) !== -1
    },
    filterChange: function () {
      // 这里每当输入的数据有变化就触发原生的过滤节点这个函数
      this.$refs.treeList.filter(this.searchName)
    }
  }
}
</script>

<style>
</style>
